<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;

class WechatMassLog extends Model
{
    use  Notifiable;
    protected $table = 'wechat_mass_logs';
    protected $fillable = [
        'type','source_id','content','w_id','status','sender_id','checker_id','check_status','reply'
    ];
    public function Wechats()
    {
        return $this->hasOne('App\Models\WeChat','id','w_id');
    }
    protected $appends = ['art','img','video','voice'];
    public function getImgAttribute()
    {
        if($this->attributes['source_id']&&$this->attributes['type']==2){
            $model = WeChatImgSource::query()->where('id',$this->attributes['source_id'])->first();
            return $model;
        }else{
            return null;
        }

    }
    public function getArtAttribute()
    {
        if($this->attributes['source_id']&&$this->attributes['type']==3){
            $model = WechatArtSource::with('contexts')->where('id',$this->attributes['source_id'])->first();
            return $model;
        }else{
            return null;
        }

    }

    public function getVoiceAttribute()
    {
        if($this->attributes['source_id']&&$this->attributes['type']==4){
            $model = WechatVideoSource::query()->where('id',$this->attributes['source_id'])->first();
            return $model;
        }else{
            return null;
        }

    }
    public function getVideoAttribute()
    {
        if($this->attributes['source_id']&&$this->attributes['type']==5){
            $model =WechatVideoSource::query()->where('id',$this->attributes['source_id'])->first();
            return $model;
        }else{
            return null;
        }

    }
}
